package net.xinqushi.design.delegate;

/**
 * 责任委托模式,SpringMVC源码中DispatcherServlet委托HandlerMapping，HandlerAdapter，ViewResolver，View
 */
public class Delegate {
}

class Boss{
    // B is a part of A(Composition组合/aggregation)
    private Worker tempWorker = new Worker();
    void tempWork(){tempWorker.tempWork();}

    // A use B
    void work(Worker worker){
        worker.work();
    }

    //A has B (Association , 聚集)
    private Worker asWorker;

    public Boss(){}
    public Boss(Worker asWorker){this.asWorker = asWorker;}

    //注: 聚集，和组合的关系是， 聚集的一种方式是wrapper ， 而组合是存在的对象，不能缺少。聚集可以不使用委任对象，组合必须使用。

}

class Worker{
    void work(){
        System.out.println("working");
    }

    void tempWork(){
        System.out.println(" temp working");
    }
}
